import { getTemplate, getSlotTemplate, getStringTypeAttr } from '@/components/template'
import { Radio } from '@/components/data'
import store from '@/store/index.js'
import { deepCopy } from '@/utils/help.js'
var handle = function (_attr, _slots, info, slotTag) {
  //定义默认属性
  let attributes = Radio,
    slots = {
      default: [],
    }

  //覆盖默认属性
  Object.assign(slots, _slots)
  let attr = Object.assign(attributes, _attr)

  Object.assign(attr, slotTag)

  //根据组件不同需要做的不同操作

  //获取插槽模板内容
  var subContent = getSlotTemplate(slots)
  //设置当前组件的slot
  if (attributes.slot && attributes.slot !== 'default') {
    attributes.slot = {
      type: 'text',
      value: attributes.slot,
    }
  } else {
    attributes.slot = {
      type: 'text',
      value: '',
    }
  }

  //字符串模板操作
  let stringAttr = getStringTypeAttr(attributes)
  let template = `<Radio 
                        ${stringAttr}>
                        ${subContent}
                    </Radio>`
  if (info.id && slotTag) {
    let components = deepCopy(store.state.components)
    components.forEach((i) => {
      if (i.info.id == info.id) {
        i.attributes = attributes
        i.template = template
      }
    })

    store.commit('setState', { components })
  }
  return { template, attributes, slots }
}
export default handle
